package io.yizoo.business.controller;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.pagehelper.PageHelper;
import io.yizoo.business.entity.*;
import io.yizoo.business.mapper.biz_analysis_cockpitMapper;
import io.elm.core.CoreController;
import io.yizoo.system.entity.fw_flowins;
import io.yizoo.system.entity.fw_flowins_yw;
import io.yizoo.system.entity.sys_org;
import io.yizoo.system.entity.sys_user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;

@RestController
@RequestMapping("/business/analysis/cockpit")
public class analysis_cockpitController extends CoreController {
    @Autowired
    private biz_analysis_cockpitMapper biz_analysis_cockpitMapper;

    //查询成本支出-当年
    @PostMapping("/GetCostData")
    public Object GetCostData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        List<Map<String, Object>> list = biz_analysis_cockpitMapper.SelectCostData(pData);
        return JsonResult(list);
    }

    //查询收入统计-当年
    @PostMapping("/GetIncomeData")
    public Object GetIncomeData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        List<Map<String, Object>> list = biz_analysis_cockpitMapper.SelectIncomeData(pData);

        BigDecimal pjIncome = BigDecimal.ZERO; //项目收入
        BigDecimal orderIncome = BigDecimal.ZERO; //订单收入
        BigDecimal otherIncome = BigDecimal.ZERO; //其他收入
        for (Map<String, Object> map : list) {
            String pj_id = (String) map.get("pj_id");
            String order_id = (String) map.get("order_id");
            if (pj_id != null && !pj_id.isEmpty()) {
                pjIncome = pjIncome.add((BigDecimal) map.get("sk_amount"));
            } else if (order_id != null && !order_id.isEmpty()) {
                orderIncome = orderIncome.add((BigDecimal) map.get("sk_amount"));
            } else {
                otherIncome = otherIncome.add((BigDecimal) map.get("sk_amount"));
            }
        }

        List<KV> listData = new ArrayList<KV>();
        listData.add(new KV("项目收入", pjIncome));
        listData.add(new KV("订单收入", orderIncome));
        listData.add(new KV("其他收入", otherIncome));
        return JsonResult(listData);
    }

    //查询项目运行情况
    @PostMapping("/GetPjPlanData")
    public Object GetPjPlanData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        if (objectNode.has("pageNum") && objectNode.has("pageSize")) {
            int pageNum = objectNode.get("pageNum").asInt();
            int pageSize = objectNode.get("pageSize").asInt();
            PageHelper.startPage(pageNum, pageSize);
        }
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        List<Map<String, Object>> list = biz_analysis_cockpitMapper.SelectPjPlanData(pData);
        return JsonResultPage(list);
    }

    //查询经营月表-当年
    @PostMapping("/GetMonthTabData")
    public Object GetMonthTabData(@RequestBody String jsonStr) {
        List<?> list = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .From(biz_bms_month_tab.class)
                        .IsWhere("and this_month = #{now_year}", "now_year")
                        .OrderBy("this_month desc")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(list);
    }

    //查询经营趋势-当年（old 已弃用 直接查询数据库）
    @PostMapping("/GetBizTrendDataOld")
    public Object GetBizTrendDataOld(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        //今年
        pData.put("now_year", objectNode.get("now_year").asInt());
        //去年
        pData.put("prev_year", objectNode.get("now_year").asInt() - 1);
        List<Map<String, Object>> list = biz_analysis_cockpitMapper.SelectBizTrendData(pData);

        List<Map<String, Object>> result = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            String month = String.format("%02d", i + 1); //生成月份
            BigDecimal netProfitNowYear = BigDecimal.ZERO; //今年净利润
            BigDecimal netProfitPrevYear = BigDecimal.ZERO; //去年净利润

            // 查找当前月份的数据
            for (Map<String, Object> entry : list) {
                String thisMonth = (String) entry.get("this_month");
                String yearType = (String) entry.get("year_type");
                BigDecimal netProfit = new BigDecimal(entry.get("net_profit").toString());

                if (thisMonth.endsWith(month)) {
                    if ("now_year".equals(yearType)) {
                        netProfitNowYear = netProfit;
                    } else if ("prev_year".equals(yearType)) {
                        netProfitPrevYear = netProfit;
                    }
                }
            }

            // 计算同比增长率：(今年同期净利润 - 去年同期净利润) / 去年同期净利润 * 100%
            BigDecimal growthRate = BigDecimal.ZERO;
            if (netProfitPrevYear.compareTo(BigDecimal.ZERO) != 0 && netProfitNowYear.compareTo(BigDecimal.ZERO) != 0) {
                growthRate = netProfitNowYear.subtract(netProfitPrevYear)
                        .divide(netProfitPrevYear.abs(), 4, BigDecimal.ROUND_HALF_UP)
                        .multiply(new BigDecimal("100"));
            } else {
                growthRate = null; // 如果上一年净利润为0，标记为null
            }

            // 封装结果
            Map<String, Object> monthlyData = new HashMap<>();
            monthlyData.put("month", month);
            monthlyData.put("net_profit_now_year", netProfitNowYear);
            monthlyData.put("net_profit_prev_year", netProfitPrevYear);
            monthlyData.put("growth_rate", growthRate);
            result.add(monthlyData);
        }
        return JsonResult(result);
    }

    /**
     * 查询经营趋势-当年
     * 注意 统一单位 万元
     * 总收入：订单 + 合同 + 项目（未关联订单、合同的项目）
     * 毛利：总收入 - 项目成本 - 外委
     * 净利润： 总收入 - 项目成本 - 外委 - 人工成本
     * @param jsonStr
     * @return ArrayList<Map<String, Object>>
     * 其中，Map的key为：
     * month：月份，值为：1~12月
     * net_profit_now_year：今年净利润
     * net_profit_prev_year：去年净利润
     * growth_rate：同比增长率
     * 其中，同比增长率的计算方式为：(今年同期净利润 - 去年同期净利润) / |去年同期净利润| * 100%
     */
    @PostMapping("/GetBizTrendData")
    public Object GetBizTrendData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);

        int now_year = objectNode.get("now_year").asInt(); //今年
        int prev_year = objectNode.get("now_year").asInt() - 1; //去年

        //查询今年和去年的所有数据
        //订单收入-万元
        List<Map<String, Object>> dd_income_list = Ctor.CoreMapper.USelectList(
                Ctor.DMaker().Selector
                        .putFactorItem("now_year", now_year)
                        .putFactorItem("prev_year", prev_year)
                        .Select("*")
                        .From(biz_cmis_order.class)
                        .Where("and status != '已取消'")
                        .IsWhere("and ( YEAR(order_date) = #{now_year} or YEAR(order_date) = #{prev_year} )")
                        .GetFactor()
        );

        //合同收入-万元
        List<Map<String, Object>> ht_income_list = Ctor.CoreMapper.USelectList(
                Ctor.DMaker().Selector
                        .putFactorItem("now_year", now_year)
                        .putFactorItem("prev_year", prev_year)
                        .Select("*")
                        .From(biz_cmis_contracts.class)
                        .Where("and status != '作废'")
                        .IsWhere("and ( YEAR(contract_date) = #{now_year} or YEAR(contract_date) = #{prev_year} )")
                        .GetFactor()
        );

        //项目收入-万元
        List<Map<String, Object>> pj_income_list = Ctor.CoreMapper.USelectList(
                Ctor.DMaker().Selector
                        .putFactorItem("now_year", now_year)
                        .putFactorItem("prev_year", prev_year)
                        .Select("*")
                        .From(biz_pmis_pj.class)
                        .Where("and contract_key IS NULL and order_key IS NULL")
                        .IsWhere("and ( YEAR(b_sdate) = #{now_year} or YEAR(b_sdate) = #{prev_year} )")
                        .GetFactor()
        );

        //项目成本（报销）-元
        List<Map<String, Object>> pj_cost_list = Ctor.CoreMapper.USelectList(
                Ctor.DMaker().Selector
                        .putFactorItem("now_year", now_year)
                        .putFactorItem("prev_year", prev_year)
                        .Select("*")
                        .From(biz_bms_reim.class)
                        .IsWhere("and ( YEAR(sys_createtime) = #{now_year} or YEAR(sys_createtime) = #{prev_year} )")
                        .GetFactor()
        );

        //外委成本（支出合同）-万元
        List<Map<String, Object>> ww_cost_list = Ctor.CoreMapper.USelectList(
                Ctor.DMaker(jsonStr).Selector
                        .putFactorItem("now_year", now_year)
                        .putFactorItem("prev_year", prev_year)
                        .Select("*")
                        .From(biz_cmis_contracts_zc.class)
                        .Where("and status != '作废'")
                        .IsWhere("and ( YEAR(contract_date) = #{now_year} or YEAR(contract_date) = #{prev_year} )")
                        .GetFactor()
        );

        //人工成本（薪资）-元
        List<Map<String, Object>> rg_cost_list = Ctor.CoreMapper.USelectList(
                Ctor.DMaker(jsonStr).Selector
                        .putFactorItem("now_year", now_year)
                        .putFactorItem("prev_year", prev_year)
                        .Select("*")
                        .From(biz_hrm_salary.class)
                        .Where("and status = '1'")
                        .IsWhere("and ( SUBSTRING(month, 1, 4) = #{now_year} or SUBSTRING(month, 1, 4) = #{prev_year} )")
                        .GetFactor()
        );

        //最终结果集-用于Echarts渲染
        List<Map<String, Object>> list = new ArrayList<>();
        //用于二级穿透页 展现详细数据
        List<Map<String, Object>> info = new ArrayList<>();

        BigDecimal totalIncomeNowYear = BigDecimal.ZERO; //今年总收入
        BigDecimal ddIncomeNowYear = BigDecimal.ZERO; //今年订单收入
        BigDecimal htIncomeNowYear = BigDecimal.ZERO; //今年合同收入
        BigDecimal pjIncomeNowYear = BigDecimal.ZERO; //今年项目收入

        BigDecimal totalCostNowYear = BigDecimal.ZERO; //今年总成本
        BigDecimal pjCostNowYear = BigDecimal.ZERO; //今年项目成本
        BigDecimal wwCostNowYear = BigDecimal.ZERO; //今年外委成本
        BigDecimal rgCostNowYear = BigDecimal.ZERO; //今年人工成本

        BigDecimal totalIncomePrevYear = BigDecimal.ZERO; //去年总收入
        BigDecimal ddIncomePrevYear = BigDecimal.ZERO; //去年订单收入
        BigDecimal htIncomePrevYear = BigDecimal.ZERO; //去年合同收入
        BigDecimal pjIncomePrevYear = BigDecimal.ZERO; //去年项目收入

        BigDecimal totalCostPrevYear = BigDecimal.ZERO; //去年总成本
        BigDecimal pjCostPrevYear = BigDecimal.ZERO; //去年项目成本
        BigDecimal wwCostPrevYear = BigDecimal.ZERO; //去年外委成本
        BigDecimal rgCostPrevYear = BigDecimal.ZERO; //去年人工成本

        BigDecimal netProfitNowYear = BigDecimal.ZERO; //今年净利润
        BigDecimal netProfitPrevYear = BigDecimal.ZERO; //去年净利润
        BigDecimal growthRate = BigDecimal.ZERO; //同比增长率

        for (int i = 0; i < 12; i++) {
            String month = String.format("%02d", i + 1);
            //今年i月总收入（今年i月 订单+合同+项目）-万元
            ddIncomeNowYear = filterDataList(dd_income_list, now_year, month, "dd_income");
            htIncomeNowYear = filterDataList(ht_income_list, now_year, month, "ht_income");
            pjIncomeNowYear = filterDataList(pj_income_list, now_year, month, "pj_income");
            totalIncomeNowYear = ddIncomeNowYear.add(htIncomeNowYear).add(pjIncomeNowYear);

            //今年i月总成本（今年i月 项目成本+外委+人工成本）
            pjCostNowYear = filterDataList(pj_cost_list, now_year, month, "pj_cost"); //项目成本-报销-元
            pjCostNowYear = pjCostNowYear.divide(new BigDecimal("10000")); //换算为万元

            wwCostNowYear = filterDataList(ww_cost_list, now_year, month, "ww_cost"); //外委-支出合同-万元
            rgCostNowYear = filterDataList(rg_cost_list, now_year, month, "rg_cost"); //人工成本-薪资-元
            rgCostNowYear = rgCostNowYear.divide(new BigDecimal("10000")); //换算为万元

            totalCostNowYear = pjCostNowYear.add(wwCostNowYear).add(rgCostNowYear);

            //去年i月总收入（去年i月 订单+合同+项目）
            ddIncomePrevYear = filterDataList(dd_income_list, prev_year, month, "dd_income");
            htIncomePrevYear = filterDataList(ht_income_list, prev_year, month, "ht_income");
            pjIncomePrevYear = filterDataList(pj_income_list, prev_year, month, "pj_income");
            totalIncomePrevYear = ddIncomePrevYear.add(htIncomePrevYear).add(pjIncomePrevYear);

            //去年i月总成本（去年i月 项目成本+外委+人工成本）
            pjCostPrevYear = filterDataList(pj_cost_list, prev_year, month, "pj_cost");
            pjCostPrevYear = pjCostPrevYear.divide(new BigDecimal("10000"));

            wwCostPrevYear = filterDataList(ww_cost_list, prev_year, month, "ww_cost");
            rgCostPrevYear = filterDataList(rg_cost_list, prev_year, month, "rg_cost");
            rgCostPrevYear = rgCostPrevYear.divide(new BigDecimal("10000"));

            totalCostPrevYear = pjCostPrevYear.add(wwCostPrevYear).add(rgCostPrevYear);

            //今年i月净利润 = 今年i月总收入 - 今年i月总成本
            netProfitNowYear = totalIncomeNowYear.subtract(totalCostNowYear);
            //去年i月净利润
            netProfitPrevYear = totalIncomePrevYear.subtract(totalCostPrevYear);

            //计算同比增长率
            if (netProfitPrevYear.compareTo(BigDecimal.ZERO) != 0 && netProfitNowYear.compareTo(BigDecimal.ZERO) != 0) {
                growthRate = netProfitNowYear.subtract(netProfitPrevYear)
                        .divide(netProfitPrevYear.abs(), 4, BigDecimal.ROUND_HALF_UP)
                        .multiply(new BigDecimal("100"));
            } else {
                growthRate = null; // 如果上一年净利润为0，标记为null
            }

            // 封装结果
            Map<String, Object> monthlyData = new HashMap<>();
            monthlyData.put("month", month);
            monthlyData.put("net_profit_now_year", netProfitNowYear);
            monthlyData.put("net_profit_prev_year", netProfitPrevYear);
            monthlyData.put("growth_rate", growthRate);
            list.add(monthlyData);

            // 封装结果
            Map<String, Object> infoData = new HashMap<>();
            infoData.put("month", i+1+"月");
            infoData.put("dd_income_now_year", ddIncomeNowYear);
            infoData.put("ht_income_now_year", htIncomeNowYear);
            infoData.put("pj_income_now_year", pjIncomeNowYear);
            infoData.put("total_income_now_year", totalIncomeNowYear);

            infoData.put("pj_cost_now_year", pjCostNowYear);
            infoData.put("ww_cost_now_year", wwCostNowYear);
            infoData.put("rg_cost_now_year", rgCostNowYear);
            infoData.put("total_cost_now_year", totalCostNowYear);

            infoData.put("dd_income_prev_year", ddIncomePrevYear);
            infoData.put("ht_income_prev_year", htIncomePrevYear);
            infoData.put("pj_income_prev_year", pjIncomePrevYear);
            infoData.put("total_income_prev_year", totalIncomePrevYear);

            infoData.put("pj_cost_prev_year", pjCostPrevYear);
            infoData.put("ww_cost_prev_year", wwCostPrevYear);
            infoData.put("rg_cost_prev_year", rgCostPrevYear);
            infoData.put("total_cost_prev_year", totalCostPrevYear);

            infoData.put("net_profit_now_year", netProfitNowYear);
            infoData.put("net_profit_prev_year", netProfitPrevYear);
            infoData.put("growth_rate", growthRate);
            info.add(infoData);
        }
        Map<String, Object> result = new HashMap<>();
        result.put("list", list);
        result.put("info", info);
        return JsonResult(result);
    }

    //筛选某年某月的 订单 |合同 |项目 并求和
    private BigDecimal filterDataList(List<Map<String, Object>> dataList, int year, String month, String flag) {
        BigDecimal result = BigDecimal.ZERO;
        List<Map<String, Object>> filterList = new ArrayList<>();

        String amountFiled = "amount";
        switch (flag) {
            case "dd_income":
                for (Map<String, Object> map : dataList) {
                    LocalDateTime orderDate = (LocalDateTime) map.get("order_date");
                    if (orderDate != null && orderDate.getYear() == year && orderDate.getMonthValue() == Integer.parseInt(month)) {
                        filterList.add(map);
                    }
                }
                amountFiled = "total_amount";
                break;
            case "ht_income":
            case "ww_cost":
                for (Map<String, Object> map : dataList) {
                    Date contractDate = (Date) map.get("contract_date");
                    if (contractDate != null) {
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(contractDate);
                        if (cal.get(Calendar.YEAR) == year && cal.get(Calendar.MONTH) + 1 == Integer.parseInt(month)) {
                            filterList.add(map);
                        }
                    }
                }
                amountFiled = "amount";
                break;
            case "pj_income":
                for (Map<String, Object> map : dataList) {
                    Date bSdate = (Date) map.get("b_sdate");
                    if (bSdate != null) {
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(bSdate);
                        if (cal.get(Calendar.YEAR) == year && cal.get(Calendar.MONTH) + 1 == Integer.parseInt(month)) {
                            filterList.add(map);
                        }
                    }
                }
                amountFiled = "money";
                break;
            case "pj_cost":
                for (Map<String, Object> map : dataList) {
                    LocalDateTime bxDate = (LocalDateTime) map.get("sys_createtime");
                    if (bxDate != null && bxDate.getYear() == year && bxDate.getMonthValue() == Integer.parseInt(month)) {
                        filterList.add(map);
                    }
                }
                amountFiled = "col_3";
                break;
            case "rg_cost":
                for (Map<String, Object> map : dataList) {
                    String dateStr = (String) map.get("month");
                    if (Integer.parseInt(dateStr.substring(0, 4)) == year && Integer.parseInt(dateStr.substring(4, 6)) == Integer.parseInt(month)) {
                        filterList.add(map);
                    }
                }
                amountFiled = "cope_salary";
                break;
            default:
                break;
        }

        for (Map<String, Object> map : filterList) {
            Object amountObj = map.get(amountFiled);
            if (amountObj != null) {
                result = result.add(new BigDecimal(amountObj.toString()));
            }
        }

        return result;
    }


    //查询经营月表汇总
    @PostMapping("/GetMonthData")
    public Object GetMonthData(@RequestBody String[] jsonStr) {
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("this_months", jsonStr);
        List<Map<String, Object>> list = biz_analysis_cockpitMapper.SelectMonthData(pData);
        return JsonResult(list);
    }

    //成本支出-数据穿透
    @PostMapping("/GetCostList")
    public Object GetCostList(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("a.col_1 AS item_type, a.col_2 AS invoice_type, a.col_4 AS cost_amount, b.sys_createtime, c.nick_name")
                        .From(fw_com_sub.class, "a")
                        .LeftJoin(biz_bms_reim.class,"b", "a.biz_id = b.id")
                        .LeftJoin(sys_user.class,"c", "b.sys_createuser = c.id")
                        .IsWhere("and YEAR ( b.sys_createtime ) = #{now_year}", "now_year")
                        .IsWhere("and a.col_1 like concat('%', #{name}, '%')", "name")
                        .OrderBy("b.sys_createtime desc")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

    //收入统计-数据穿透
    @PostMapping("/GetIncomeList")
    public Object GetIncomeList(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("a.*, b.name as sk_person_name")
                        .From(biz_bms_receipt.class, "a")
                        .LeftJoin(biz_hrm_ei_basic.class,"b", "b.emp_code = a.sk_person")
                        .IsWhere("and YEAR(a.sk_date) = #{now_year}", "now_year")
                        .IsWhere("and a.remark like concat('%', #{remark}, '%')", "remark")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

    //项目运行-数据穿透
    @PostMapping("/GetPjList")
    public Object GetPjList(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("pj.*, type.name as type_mc, org.name as org_mc, ei.name AS manager_mc, CASE WHEN (b_edate < CURDATE() AND progress < 100) THEN DATEDIFF( CURDATE(), b_edate ) ELSE 0 END AS delay_days")
                        .From(biz_pmis_pj.class, "pj")
                        .LeftJoin(biz_pmis_pj_type.class,"type", "pj.type = type.id")
                        .LeftJoin(sys_org.class,"org", "pj.org = org.id")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei", "pj.manager = ei.emp_code")
                        .IsWhere("and YEAR(pj.b_sdate) = #{now_year}", "now_year")
                        .IsWhere("and pj.name like concat('%', #{name}, '%')", "name")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

    //项目详情-数据穿透
    @PostMapping("/GetPjInfo")
    public Object GetPjInfo(@RequestBody String jsonStr) {
        Object ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("pj.*, type.name as type_mc, org.name as org_mc, ei.name AS manager_mc, ei_booker.NAME AS booker_mc, ei_saler.NAME AS saler_mc")
                        .From(biz_pmis_pj.class, "pj")
                        .LeftJoin(biz_pmis_pj_type.class,"type", "pj.type = type.id")
                        .LeftJoin(sys_org.class,"org", "pj.org = org.id")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei", "pj.manager = ei.emp_code")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei_booker", "pj.booker = ei_booker.emp_code")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei_saler", "pj.saler = ei_saler.emp_code")
                        .Where("and pj.id = #{pj_id}", "pj_id")
                        .GetFactor());
        return JsonResult(ret);
    }

    //---------------------------新版大屏设计图-------------
    //合同订单-结算情况（查询当年 已结算金额：合同额+订单额 / 未结算金额）
    @PostMapping("/GetSettlementData")
    public Object GetSettlementData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        //已结算：结算表 查询条件：关联订单 或 关联合同 或 关联项目
        BigDecimal total_js;
        total_js = biz_analysis_cockpitMapper.SelectJsData(pData);

        //订单总额：下单时间-本年度
        BigDecimal total_dd = biz_analysis_cockpitMapper.SelectDdTotalData(pData);
        //合同总额：签订时间-本年度
        BigDecimal total_ht = biz_analysis_cockpitMapper.SelectHtTotalData(pData);
        //项目总额：未关联 订单、合同 的项目
        BigDecimal total_pj = biz_analysis_cockpitMapper.SelectPjTotalData(pData);

        //未结算：订单总额 + 合同总额 + 项目总额 - 已结算金额
        BigDecimal total_wjs;
        total_wjs = total_dd.add(total_ht).add(total_pj).subtract(total_js);

        Map<String, Object> result = new HashMap<>();
        result.put("total_js", total_js);
        result.put("total_wjs", total_wjs);
        return JsonResult(result);
    }

    //合同订单-结算情况-已结算 数据穿透（收款表: 关联订单 或 关联合同 或 关联项目）
    @PostMapping("/GetJsList")
    public Object GetJsList(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        List<Map<String, Object>> list;
        if ("all".equals(objectNode.get("flag").asText())) { //查询所有
            list = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("a.*, b.name as ei_name")
                            .From(biz_bms_settlement.class, "a")
                            .LeftJoin(biz_hrm_ei_basic.class,"b", "b.emp_code = a.sk_person")
                            .Where("AND js_status = '已结算'")
                            .IsWhere("and YEAR(a.js_date) = #{now_year}", "now_year")
                            .IsPage()
                            .GetFactor());
        } else { //查询部分
            list = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("a.*, b.name as ei_name")
                            .From(biz_bms_settlement.class, "a")
                            .LeftJoin(biz_hrm_ei_basic.class,"b", "b.emp_code = a.sk_person")
                            .Where("and (pj_id IS NOT NULL OR order_id IS NOT NULL OR contract_id IS NOT NULL)")
                            .Where("AND js_status = '已结算'")
                            .IsWhere("and YEAR(a.js_date) = #{now_year}", "now_year")
                            .IsPage()
                            .GetFactor());
        }
        return JsonResultPage(list);
    }

    //合同订单-结算情况-未结算 数据穿透（收款表: 关联订单 或 关联合同 或 关联项目）
    @PostMapping("/GetWjsList")
    public Object GetWjsList(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);

        if (objectNode.has("pageNum") && objectNode.has("pageSize")) {
            int pageNum = objectNode.get("pageNum").asInt();
            int pageSize = objectNode.get("pageSize").asInt();
            PageHelper.startPage(pageNum, pageSize);
        }

        List<Map<String, Object>> factors = new ArrayList<>();
        //查询订单-未结算（收款表中没有对应收款记录的订单）
        Map<String, Object> dd_factor = Ctor.DMaker(jsonStr).Selector
                .Select("a.order_name as name, '订单' as ltype, total_amount, a.order_date as ldate")
                .From(biz_cmis_order.class, "a")
                .LeftJoin(biz_bms_receipt.class,"c", "c.order_id = a.sys_code_key")
                .Where("and c.order_id IS NULL")
                .IsWhere("and YEAR(a.order_date) = #{now_year}", "now_year")
                .GetFactor();

        //查询合同-未结算
        Map<String, Object> ht_factor = Ctor.DMaker(jsonStr).Selector
                .Select("a.contract_name as name, '合同' as ltype, amount as total_amount, a.contract_date as ldate")
                .From(biz_cmis_contracts.class, "a")
                .LeftJoin(biz_bms_receipt.class,"c", "c.contract_id = a.sys_code_key")
                .Where("and c.contract_id IS NULL")
                .IsWhere("and YEAR(a.contract_date) = #{now_year}", "now_year")
                .GetFactor();

        //查询项目-未结算（未关联订单与合同）
        Map<String, Object> pj_factor = Ctor.DMaker(jsonStr).Selector
                .Select("a.name, '项目' as ltype, money as total_amount, a.b_sdate as ldate")
                .From(biz_pmis_pj.class, "a")
                .LeftJoin(biz_bms_receipt.class,"c", "c.contract_id = a.sys_code_key")
                .Where("and a.order_key IS NULL and a.contract_key IS NULL")
                .Where("and c.pj_id IS NULL")
                .IsWhere("and YEAR(a.b_sdate) = #{now_year}", "now_year")
                .GetFactor();

        factors.add(dd_factor);
        factors.add(ht_factor);
        factors.add(pj_factor);

        Map<String, Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        pData.put("factors", factors);
        List<Map<String, Object>> wjsList = Ctor.CoreMapper.UUnion(pData);

        return JsonResultPage(wjsList);
    }

    //项目承揽数量（查询当年 每个月份的项目承揽数量） 开工日期
    @PostMapping("/GetPjCountData")
    public Object GetPjCountData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        List<Map<String, Object>> list = biz_analysis_cockpitMapper.SelectPjCountData(pData);

        Map<Integer, Integer> resultMap = new HashMap<>();
        for (int i = 1; i <= 12; i++) {
            resultMap.put(i, 0);
        }

        for (Map<String, Object> row : list) {
            int month = (int) row.get("month");
            long pj_count = (long) row.get("pj_count");
            int count = (int) pj_count;
            resultMap.put(month, count);
        }

        List<Map<String, Object>> result = new ArrayList<>();
        resultMap.forEach((month, count) -> {
            Map<String, Object> entry = new HashMap<>();
            entry.put("month", month);
            entry.put("pj_count", count);
            result.add(entry);
        });
        return JsonResult(result);
    }

    //项目承揽数量-数据穿透
    @PostMapping("/GetPjNumList")
    public Object GetPjNumList(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("pj.*, type.name as type_mc, org.name as org_mc, ei.name AS manager_mc")
                        .From(biz_pmis_pj.class, "pj")
                        .LeftJoin(biz_pmis_pj_type.class,"type", "pj.type = type.id")
                        .LeftJoin(sys_org.class,"org", "pj.org = org.id")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei", "pj.manager = ei.emp_code")
                        .IsWhere("and DATE_FORMAT(pj.b_sdate, '%Y-%m') = #{now_year}", "now_year")
                        .IsWhere("and pj.name like concat('%', #{name}, '%')", "name")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

    //异常预警（查询当年 项目异常：延期即为异常 / 指派异常：延期-到截止时间未完成）
    @PostMapping("/GetWarningData")
    public Object GetWarningData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        //项目列表
        List<Map<String, Object>> pjList = biz_analysis_cockpitMapper.SelectPjPlanData(pData);
        //指派列表
        List<Map<String, Object>> zpList = biz_analysis_cockpitMapper.SelectRwzpData(pData);

        Map<String, Object> result = new HashMap<>();
        result.put("pj_list", pjList);
        result.put("zp_list", zpList);
        return JsonResult(result);
    }

    //项目异常-数据穿透
    @PostMapping("/GetPjWarningList")
    public Object GetPjWarningList(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        List<Map<String, Object>> pjList;
        if ("异常".equals(objectNode.get("state").asText())) {
            pjList = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("pj.*, ei.name AS ei_name, CASE WHEN (b_edate < CURDATE() AND progress < 100) THEN DATEDIFF(CURDATE(), b_edate) ELSE 0 END AS delay_days")
                            .From(biz_pmis_pj.class, "pj")
                            .LeftJoin(biz_hrm_ei_basic.class,"ei", "pj.manager = ei.emp_code")
                            .Where("AND (b_edate < CURDATE() AND progress < 100)")
                            .IsWhere("and YEAR(pj.b_sdate) = #{now_year}", "now_year")
                            .IsWhere("and pj.name like concat('%', #{name}, '%')", "name")
                            .IsPage()
                            .GetFactor()
            );
        } else {
            pjList = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("pj.*, ei.name AS ei_name, CASE WHEN (b_edate < CURDATE() AND progress < 100) THEN DATEDIFF(CURDATE(), b_edate) ELSE 0 END AS delay_days")
                            .From(biz_pmis_pj.class, "pj")
                            .LeftJoin(biz_hrm_ei_basic.class,"ei", "pj.manager = ei.emp_code")
                            .Where("AND ((b_edate IS NULL) or (b_edate >= CURDATE()) or (progress >= 100))")
                            .IsWhere("and YEAR(pj.b_sdate) = #{now_year}", "now_year")
                            .IsWhere("and pj.name like concat('%', #{name}, '%')", "name")
                            .IsPage()
                            .GetFactor()
            );
        }
        return JsonResultPage(pjList);
    }

    //指派异常-数据穿透
    @PostMapping("/GetZpWarningList")
    public Object GetZpWarningList(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        List<Map<String, Object>> zpList;
        if ("异常".equals(objectNode.get("state").asText())) {
            zpList = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("rwzp.*, ei.name AS ei_name, CASE WHEN (jh_end_time < CURDATE() AND status != '已完成') THEN DATEDIFF(CURDATE(), jh_end_time) ELSE 0 END AS delay_days")
                            .From(biz_pmis_rwzp.class, "rwzp")
                            .LeftJoin(biz_hrm_ei_basic.class,"ei", "rwzp.to_person = ei.emp_code")
                            .Where("AND (jh_end_time < CURDATE() AND status != '已完成')")
                            .IsWhere("and YEAR(rwzp.start_time) = #{now_year}", "now_year")
                            .IsWhere("and ei.name like concat('%', #{ei_name}, '%')", "ei_name")
                            .IsPage()
                            .GetFactor()
            );
        } else{
            zpList = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("rwzp.*, ei.name AS ei_name, CASE WHEN (jh_end_time < CURDATE() AND status != '已完成') THEN DATEDIFF(CURDATE(), jh_end_time) ELSE 0 END AS delay_days")
                            .From(biz_pmis_rwzp.class, "rwzp")
                            .LeftJoin(biz_hrm_ei_basic.class,"ei", "rwzp.to_person = ei.emp_code")
                            .Where("AND ((jh_end_time >= CURDATE() or status = '已完成'))")
                            .IsWhere("and YEAR(rwzp.start_time) = #{now_year}", "now_year")
                            .IsWhere("and ei.name like concat('%', #{ei_name}, '%')", "ei_name")
                            .IsPage()
                            .GetFactor()
            );
        }
        return JsonResultPage(zpList);
    }

    /**
     * 收入统计（查询当年 合同收入、结算收入）
     * 成本支出（查询当年 项目成本-报销费用 不含外委、人工成本-薪酬、外委-甲方结算 支出结算）
     * 注意统一单位 万元、元
     * @param jsonStr
     * @return
     */
    @PostMapping("/GetInCostData")
    public Object GetInCostData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        //合同收入（已签订合同、已下单订单）万元
        BigDecimal totalHt = biz_analysis_cockpitMapper.SelectHtSum(pData);
        BigDecimal totalDD = biz_analysis_cockpitMapper.SelectDDSum(pData);
        BigDecimal totalHtIncome = totalHt.add(totalDD);

        //结算收入（已开发票）万元
        BigDecimal totalJsIncome = biz_analysis_cockpitMapper.SelectJsSum(pData);

        //查询项目成本（报销的费用、不含外委）元
        BigDecimal pjCost = biz_analysis_cockpitMapper.SelectPjCostSum(pData);

        //查询人工成本（薪酬）元
        BigDecimal laborCost = biz_analysis_cockpitMapper.SelectLaborCostSum(pData);

        //查询外委（甲方结算、支出合同）万元
        BigDecimal outsourceCost = biz_analysis_cockpitMapper.SelectOutsourceCostSum(pData);

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("total_ht_income", totalHtIncome != null ? totalHtIncome : BigDecimal.ZERO);
        resultMap.put("total_js_income", totalJsIncome != null ? totalJsIncome : BigDecimal.ZERO);
        resultMap.put("pj_cost", pjCost != null ? pjCost : BigDecimal.ZERO);
        resultMap.put("labor_cost", laborCost != null ? laborCost : BigDecimal.ZERO);
        resultMap.put("outsource_cost", outsourceCost != null ? outsourceCost.multiply(new BigDecimal("10000")) : BigDecimal.ZERO);
        return JsonResult(resultMap);
    }

    //项目成本 - 二级穿透页面查询  报销数据
    @PostMapping("/GetPjCostList")
    public Object GetPjCostList(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("a.*, ei.name as person_name, pj.name as pj_name")
                        .From(biz_bms_reim.class, "a")
                        .LeftJoin(biz_pmis_pj.class,"pj", "pj.sys_code_key = a.col_6")
                        .LeftJoin(sys_user.class,"b", "b.id = a.sys_createuser")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei", "b.emp_code = ei.emp_code")
                        .IsWhere("and YEAR(a.sys_createtime) = #{now_year}", "now_year")
                        .IsWhere("and pj.name like concat('%', #{pj_name}, '%')", "pj_name")
                        .IsPage()
                        .GetFactor()
        );
        return JsonResultPage(ret);
    }

    //人工成本 - 二级穿透页面查询  薪酬数据
    @PostMapping("/GetLaborCostList")
    public Object GetLaborCostList(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("a.*, ei.name as ei_name, c.name as org_name")
                        .From(biz_hrm_salary.class, "a")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei", "a.emp_code = ei.emp_code")
                        .LeftJoin(sys_user.class,"b", "b.emp_code = ei.emp_code")
                        .LeftJoin(sys_org.class,"c", "c.id = b.dept_id")
                        .IsWhere("and YEAR(a.create_date) = #{now_year}", "now_year")
                        .IsWhere("and ei.name like concat('%', #{ei_name}, '%')", "ei_name")
                        .OrderBy("month desc")
                        .IsPage()
                        .GetFactor()
        );
        return JsonResultPage(ret);
    }

    //外委 - 二级穿透页面查询  甲方结算、支出合同数据
    @PostMapping("/GetOutsourceCostList")
    public Object GetOutsourceCostList(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("a.*, ei.name as person_name, co.contract_name as co_name")
                        .From(biz_bms_settlement_zc.class, "a")
                        .LeftJoin(biz_cmis_contracts_zc.class,"co", "co.sys_code_key = a.contract_id")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei", "a.sk_person = ei.emp_code")
                        .Where("and a.js_status = '已结算'")
                        .IsWhere("and YEAR(a.js_date) = #{now_year}", "now_year")
                        .IsWhere("and a.remark like concat('%', #{remark}, '%')", "remark")
                        .IsPage()
                        .GetFactor()
        );
        return JsonResultPage(ret);
    }

    //收入统计 - 合同收入 有效合同+有效订单
    @PostMapping("/GetHtIncomeList")
    public Object GetHtIncomeList(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        if (objectNode.has("pageNum") && objectNode.has("pageSize")) {
            int pageNum = objectNode.get("pageNum").asInt();
            int pageSize = objectNode.get("pageSize").asInt();
            PageHelper.startPage(pageNum, pageSize);
        }
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        List<Map<String,Object>> ht_in_list = biz_analysis_cockpitMapper.SelectHtIncomeData(pData);
        return JsonResultPage(ht_in_list);
    }

    //项目阶段（查询当年 每个进度阶段区域的项目数量）
    @PostMapping("/GetPjStageData")
    public Object GetPjStageData(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        Map<String,Object> pData = new HashMap<String,Object>();
        pData.put("now_year", objectNode.get("now_year").asText());
        Map<String, Object> result = biz_analysis_cockpitMapper.SelectPjStageData(pData);
        return JsonResult(result);
    }

    //根据项目进度查询项目列表-数据穿透
    @PostMapping("/GetPjListByProgress")
    public Object GetPjListByProgress(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        String progress = objectNode.get("progress").asText();
        String whereCon = "and pj.progress >= #{pro1} and pj.progress < #{pro2}";
        String[] progressArr;
        if (progress != null && !progress.isEmpty()) {
            progressArr = progress.split("-");
        } else {
            progressArr = new String[]{"0", "100"};
        }
        if ("100".equals(progressArr[1])) {
            whereCon = "and pj.progress >= #{pro1} and pj.progress <= #{pro2}";
        }

        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .putFactorItem("pro1", progressArr[0])
                        .putFactorItem("pro2", progressArr[1])
                        .Select("pj.*, type.name as type_mc, org.name as org_mc, ei.name AS manager_mc")
                        .From(biz_pmis_pj.class, "pj")
                        .LeftJoin(biz_pmis_pj_type.class,"type", "pj.type = type.id")
                        .LeftJoin(sys_org.class,"org", "pj.org = org.id")
                        .LeftJoin(biz_hrm_ei_basic.class,"ei", "pj.manager = ei.emp_code")
                        .IsWhere("and YEAR(pj.b_sdate) = #{now_year}", "now_year")
                        .IsWhere("and pj.name like concat('%', #{name}, '%')", "name")
                        .IsWhere(whereCon)
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

    //人员情况（查询当天 在岗、出差、请假的人员信息）
    @PostMapping("/GetEIConData")
    public Object GetEICount(@RequestBody String jsonStr) {
        //查询总人数
        int ei_count = biz_analysis_cockpitMapper.SelectEICount();
        //查询请假人数
        int leave_count = biz_analysis_cockpitMapper.SelectLeaveCount();
        //查询出差人数
        int trip_count = biz_analysis_cockpitMapper.SelectTripCount();
        //查询请假、出差人数  去重
        int work_count2 = biz_analysis_cockpitMapper.SelectWorkCount();
        int work_count = ei_count - work_count2;

        Map<String, Object> mapData = new HashMap<String, Object>();
        mapData.put("ei_count", ei_count);
        mapData.put("leave_count", leave_count);
        mapData.put("trip_count", trip_count);
        mapData.put("work_count", work_count);
        return JsonResult(mapData);
    }

    //人员情况-数据穿透
    @PostMapping("/GetEIStateList")
    public Object GetEIStateList(@RequestBody String jsonStr) {
        ObjectNode objectNode = Ctor.getObjectNode(jsonStr);
        List<Map<String, Object>> list = new ArrayList<>();
        if ("请假".equals(objectNode.get("state").asText())) {
            list = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("leave_a.sys_createtime, leave_a.col_1 AS leave_type, leave_a.col_3 AS start_date, leave_a.col_4 AS end_date, '请假中' AS work_state, user_a.nick_name, org_a.NAME AS org_name")
                            .From(biz_oa_ask_leave.class, "leave_a")
                            .LeftJoin(fw_flowins_yw.class,"yw_a", "yw_a.data_id = leave_a.id")
                            .LeftJoin(fw_flowins.class, "flowins_a", "flowins_a.id = yw_a.flow_id")
                            .LeftJoin(sys_user.class,"user_a", "leave_a.sys_createuser = user_a.id")
                            .LeftJoin(biz_hrm_ei_basic.class,"ei_a", "user_a.emp_code = ei_a.emp_code")
                            .LeftJoin(biz_hrm_ei_rel_org.class,"ei_org_a", "ei_a.id = ei_org_a.ei_id AND ei_org_a.pm = 1")
                            .LeftJoin(sys_org.class,"org_a", "org_a.id = ei_org_a.org_id")
                            .Where("and flowins_a.status = 'running'")
                            .IsWhere("and ei_a.name like concat('%', #{name}, '%')", "name")
                            .IsPage()
                            .GetFactor()
            );
        } else if ("出差".equals(objectNode.get("state").asText())) {
            list = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("trip_a.sys_createtime, trip_a.col_3 AS trip_area ,trip_a.col_4 AS start_date, trip_a.col_5 AS end_date, trip_a.col_6 AS trip_days, '出差中' AS work_state, user_a.nick_name, org_a.NAME AS org_name")
                            .From(biz_oa_business_trip.class, "trip_a")
                            .LeftJoin(fw_flowins_yw.class,"yw_a", "yw_a.data_id = trip_a.id")
                            .LeftJoin(fw_flowins.class, "flowins_a", "flowins_a.id = yw_a.flow_id")
                            .LeftJoin(sys_user.class,"user_a", "trip_a.sys_createuser = user_a.id")
                            .LeftJoin(biz_hrm_ei_basic.class,"ei_a", "user_a.emp_code = ei_a.emp_code")
                            .LeftJoin(biz_hrm_ei_rel_org.class,"ei_org_a", "ei_a.id = ei_org_a.ei_id AND ei_org_a.pm = 1")
                            .LeftJoin(sys_org.class,"org_a", "org_a.id = ei_org_a.org_id")
                            .Where("and flowins_a.status = 'running'")
                            .IsWhere("and ei_a.name like concat('%', #{name}, '%')", "name")
                            .IsPage()
                            .GetFactor()
            );
        } else if ("在岗".equals(objectNode.get("state").asText())) {
            //查询请假、出差的人员 工号
            List<String> userIds = biz_analysis_cockpitMapper.SelectLeaveTripIds();
            if (userIds == null || userIds.isEmpty()) {
                userIds = Collections.singletonList("NULL"); // 添加一个不可能存在的值
            }

            // 将 List<String> 转换为逗号分隔的字符串
            String userIdsStr = String.join("', '", userIds);
            userIdsStr = "'" + userIdsStr + "'"; // 添加单引号

            list = Ctor.CoreMapper.USelect(
                    Ctor.DMaker(jsonStr).Selector
                            .Select("ei_a.*, org_a.NAME AS org_name, '在岗' AS work_state")
                            .From(biz_hrm_ei_basic.class, "ei_a")
                            .LeftJoin(biz_hrm_ei_rel_org.class,"ei_org_a", "ei_a.id = ei_org_a.ei_id AND ei_org_a.pm = 1")
                            .LeftJoin(sys_org.class,"org_a", "org_a.id = ei_org_a.org_id")
                            .Where("and ei_a.emp_code not in ("+userIdsStr+")")
                            .IsWhere("and ei_a.name like concat('%', #{name}, '%')", "name")
                            .IsPage()
                            .GetFactor()
            );
        }
        return JsonResultPage(list);
    }

}
